<?php
namespace admin\models;
use herosphp\bean\Beans;

/**
 * 管理员模型类
 * Date: 16-10-26
 * Time: 下午5:11
 */
class Manager
{
    public $id;
    public $username;
    public $mobile;
    public $jobno;
    public $email;
    public $name;
    public $roleId;
    public $roleName;
    public $summary;
    public $lastLoginTime;
    public $lastLoginIp;
    public $status;
    public $addtime;
    public $updatetime;
    public $permissions;

    /**
     * @return mixed
     */
    public function getId()
    {
        return intval($this->id);
    }

    /**
     * @param mixed $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

    /**
     * @return mixed
     */
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * @param mixed $username
     */
    public function setUsername($username)
    {
        $this->username = $username;
    }

    /**
     * @return mixed
     */
    public function getMobile()
    {
        return $this->mobile;
    }

    /**
     * @param mixed $mobile
     */
    public function setMobile($mobile)
    {
        $this->mobile = $mobile;
    }

    /**
     * @return mixed
     */
    public function getJobno()
    {
        return $this->jobno;
    }

    /**
     * @param mixed $jobno
     */
    public function setJobno($jobno)
    {
        $this->jobno = $jobno;
    }

    /**
     * @return mixed
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * @param mixed $email
     */
    public function setEmail($email)
    {
        $this->email = $email;
    }

    /**
     * @return mixed
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param mixed $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * @return mixed
     */
    public function getRoleId()
    {
        return $this->roleId;
    }

    /**
     * @param mixed $roleId
     */
    public function setRoleId($roleId)
    {
        $this->roleId = $roleId;
    }

    /**
     * @return mixed
     */
    public function getRoleName()
    {
        return $this->roleName;
    }

    /**
     * @param mixed $roleName
     */
    public function setRoleName($roleName)
    {
        $this->roleName = $roleName;
    }

    /**
     * @return mixed
     */
    public function getSummary()
    {
        return $this->summary;
    }

    /**
     * @param mixed $summary
     */
    public function setSummary($summary)
    {
        $this->summary = $summary;
    }

    /**
     * @return mixed
     */
    public function getLastLoginTime()
    {
        return $this->lastLoginTime;
    }

    /**
     * @param mixed $lastLoginTime
     */
    public function setLastLoginTime($lastLoginTime)
    {
        $this->lastLoginTime = $lastLoginTime;
    }

    /**
     * @return mixed
     */
    public function getLastLoginIp()
    {
        return $this->lastLoginIp;
    }

    /**
     * @param mixed $lastLoginIp
     */
    public function setLastLoginIp($lastLoginIp)
    {
        $this->lastLoginIp = $lastLoginIp;
    }

    /**
     * @return mixed
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * @param mixed $status
     */
    public function setStatus($status)
    {
        $this->status = $status;
    }

    /**
     * @return mixed
     */
    public function getAddtime()
    {
        return $this->addtime;
    }

    /**
     * @param mixed $addtime
     */
    public function setAddtime($addtime)
    {
        $this->addtime = $addtime;
    }

    /**
     * @return mixed
     */
    public function getUpdatetime()
    {
        return $this->updatetime;
    }

    /**
     * @param mixed $updatetime
     */
    public function setUpdatetime($updatetime)
    {
        $this->updatetime = $updatetime;
    }

    /**
     * @return mixed
     */
    public function getPermissions()
    {
        return $this->permissions;
    }

    /**
     * @param mixed $permissions
     */
    public function setPermissions($permissions)
    {
        $this->permissions = $permissions;
    }

    /**
     * 判断某个操作是否有权限
     * @param $opt
     * @return bool
     */
    public function hasPermission($opt) {

        if ( $this->isSuperManager() ) return true;

        $operationService = Beans::get('system.operation.service');
        $operations = $operationService->getPermssionArray();
        if ( !isset($operations[$opt]) ) { //不需要判断权限的操作
            return true;
        }
        return isset($this->permissions[$opt]);
    }

    /**
     * 判断是否超级管理员
     * @return bool
     */
    public function isSuperManager() {
        return ($this->roleId == 0);
    }

}